import { makeAutoObservable, runInAction } from 'mobx'
import Service from '../service'

class cushighseaStore {
    constructor() {
        makeAutoObservable(this)
    }
    data = []
    count=null
    selectedRowKeys=[]
    highSearch= {
        contact_name:'',
        customer_id:'',
        customer_level:'',
        customer_name:'',
        customer_source:'',
        customer_type:'',
        email:'',
        end_date:'',
        entry_time:'',
        gd_next_contact:'',
        goods_type:'',
        industry:'',
        inputer:'',
        job:'',
        last_update:'',
        location:'',
        phone_number:'',
        postcode:'',
        protection:'',
        qq:'',
        region:'',
        remark:'',
        salesman:'',
        shipment_date:'',
        total_money:'',
        web :''               
    }

    //页码
    currentPage = 1 //当前页码
    pageSize = 10 //每页条数
    total=0  //总条数

    //导出数据键名对应中文
    exportData={
        customer_id:'客户id',
        customer_name:'客户名称',
        contact_id:'联系人id',
        region:'所在地区',
        location:'详细地址',
        customer_type_id:'客户类型id',
        customer_source:'客户来源',
        customer_level:'客户级别',
        industry:'行业',
        goods_type:'商品类别',
        web:'网址',
        remark:'备注',
        inputer:'录入者',
        salesman:'业务员',
        entry_time:'录入时间',
        last_update:'最后更新',
        gd_next_contact:'跟单下次联系时间',
        shipment_date:'订单交单日期',
        total_money:'合同总金额',
        arrears:'合同欠款',
        end_date:'合同到期日期',
        after_sale:'售后次数',
        accessory:'附件',
        status:'公海状态（0.放入公海，1未放入公海）',
        job_id:'Id(自增)',
        job:'职位',
        contact_name:'联系人姓名',
        sex:'性别',
        phone_number:'手机号码',
        job_id:'职位id',
        wechat:'微信',
        qq:'QQ',
        email:'电子邮箱',
        birthday:'生日',
        type:'客户类型'
    }
    changeKey(arr,key1) { 
        for (let i = 0; i < arr.length; i++) { 
            arr[i].key = arr[i][key1];
        }
    }
    getCusHighSeaMData({ currentPage, pageSize }) {
        return new Promise((resovle, reject) => {
            Service.customerhighseaService.customerhighsea.getCusHighSeaM({ currentPage, pageSize }).then((data) => {
                resovle(data)
                console.log('M页面请求成功', data);
                runInAction(() => {
                    this.data = data.data.data
                    this.changeKey(this.data, 'customer_id')
                    this.count=data.data.count
                })
            }).catch((err) => {
                reject(err)
            })
        })
    }
    getCusHighSeaResData(params) {
        return new Promise((resovle, reject) => {
            Service.customerhighseaService.customerhighsea.getCusHighSeaRes(params).then((res) => {
                resovle(res)
                console.log('请求成功', res);
                runInAction(() => {
                    this.data = res.data.data
                    this.changeKey(this.data,'customer_id')
                })
            }).catch((err) => {
                reject(err)
            })
        })
    }
    delListData({customer_id}) {
        return new Promise((resovle, reject) => {
            Service.customerhighseaService.customerhighsea.delList({customer_id}).then((res) => {
                resovle(res)
                console.log('del请求成功', res);
            }).catch((err) => {
                reject(err)
            })
        })
    }

    //待审核申请页面
    pendingAuditData({ currentPage, pageSize }) {
        return new Promise((resovle, reject) => {
            Service.customerhighseaService.customerhighsea.pendingAudit({ currentPage, pageSize }).then((data) => {
                resovle(data)
                console.log('待审核页面', data);
                runInAction(() => {
                    this.data = data.data.data
                    this.changeKey(this.data, 'customer_id')
                    this.count=data.data.count
                })
            }).catch((err) => {
                reject(err)
            })
        })
    }
     //审核通过
    applyPassData(params) {
        return new Promise((resovle, reject) => {
            Service.customerhighseaService.customerhighsea.applyPass(params).then((res) => {
                resovle(res)
                console.log('请求成功', res);
            }).catch((err) => {
                reject(err)
            })
        })
    }
     //申请
    applyData(data) {
        return new Promise((resovle, reject) => {
            Service.customerhighseaService.customerhighsea.apply(data).then((res) => {
                resovle(res)
                console.log('apply请求成功', res);
                // runInAction(() => {
                //     this.data = res.data.data
                //     this.changeKey(this.data,'customer_id')
                // })
            }).catch((err) => {
                reject(err)
                console.log(err)
            })
        })
    }

    //假数据
    CHSdata = [
        {key:1,customer_id: 1, customer_name: '大明', contact_name: '李四',phone_number:'66666666',customer_source:'电话营销',entry_time:'2022-6-6',btn_status:0,
            last_update: '1天前', user_id: null, apply_time: null
        },
        {key:2,customer_id: 2, customer_name: '大明明', contact_name: '李四',phone_number:'66666666',customer_source:'搜索引擎',entry_time:'2022-6-6',btn_status:0,
            last_update: '1天前', user_id: null, apply_time: null
        },
        {key:3,customer_id: 3, customer_name: '小明', contact_name: '哈哈哈',phone_number:'66666666',customer_source:'电话营销',entry_time:'2022-6-6',btn_status:0,
            last_update: '1天前', user_id: null, apply_time: null
        },
        {key:4,customer_id: 4, customer_name: '张三', contact_name: '王五',phone_number:'66666666',customer_source:'朋友介绍',entry_time:'2022-6-6',btn_status:0,
            last_update: '1天前', user_id: null, apply_time: null
        },
        {key:5,customer_id: 5, customer_name: '王多多', contact_name: '王多鱼',phone_number:'66666666',customer_source:'电话营销',entry_time:'2022-6-6',btn_status:0,
            last_update: '1天前', user_id: null, apply_time: null
        },
        {key:6,customer_id:6, customer_name: '二喜', contact_name: '小王',phone_number:'66666666',customer_source:'电话营销',entry_time:'2022-6-6',btn_status:1,
        last_update: '1天前', user_id: '张三', apply_time: '2022-8-8'
        },
        {key:7,customer_id: 7, customer_name: '小鱼', contact_name: '李四',phone_number:'66666666',customer_source:'搜索引擎',entry_time:'2022-6-6',btn_status:1,
            last_update: '1天前', user_id: '张三', apply_time: '2022-8-8'
        },
        {key:8,customer_id: 8, customer_name: '哈哈', contact_name: '老王',phone_number:'66666666',customer_source:'电话营销',entry_time:'2022-6-6',btn_status:1,
            last_update: '1天前', user_id: 'admin', apply_time: '2022-8-8'
        }
    ]
    CHSPdata = [
        {key:6,customer_id:6, customer_name: '二喜', contact_name: '小王',phone_number:'66666666',customer_source:'电话营销',entry_time:'2022-6-6',btn_status:1,
            last_update: '1天前', user_id: '张三', apply_time: '2022-8-8'
        },
        {key:7,customer_id: 7, customer_name: '小鱼', contact_name: '李四',phone_number:'66666666',customer_source:'搜索引擎',entry_time:'2022-6-6',btn_status:1,
            last_update: '1天前', user_id: '张三', apply_time: '2022-8-8'
        },
        {key:8,customer_id: 8, customer_name: '哈哈', contact_name: '老王',phone_number:'66666666',customer_source:'电话营销',entry_time:'2022-6-6',btn_status:1,
            last_update: '1天前', user_id: 'admin', apply_time: '2022-8-8'
        }
    ]

}
export default cushighseaStore